/**
 * @file categories/dp/monotonous_queue/acwing135/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/7/4 14:52:56
 **/

#include <iostream>

using namespace std;

typedef long long LL;
const int N = 3e5 + 10;
int n, m;
LL s[N], que[N];

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &s[i]);
    s[i] += s[i - 1];
  }
  int hh = 0, tt = 0;
  que[0] = 0;
  LL res = -1e18;
  for (int i = 1; i <= n; ++i) {
    if (hh <= tt && i - que[hh] > m) hh++;
    res = max(res, s[i] - s[que[hh]]);
    while (hh <= tt && s[que[tt]] >= s[i]) tt--;
    que[++tt] = i;
  }
  printf("%lld\n", res);
  return 0;
}
